package com.zzz;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class Producer {
    public static void main(String[] args) {
        SpringApplication.run(Producer.class, args);
    }

    @RestController
    public class TestController {

        @Autowired
        private RabbitTemplate rabbitTemplate;

        @GetMapping("/sendMsg")
        public String sendMsg() {
            // topic
            rabbitTemplate.convertAndSend("exchange", "topic.exchange", "Topic Message...");
            // fanout
//            rabbitTemplate.convertAndSend("fanoutExchange", "", "Broadcast Message...");
            // anonymous queue
            rabbitTemplate.convertAndSend("testFanout", "", "Test Broadcast Message...");
            return "success";
        }

    }

}

